const totalInput = document.getElementById('total');
const feetInput = document.getElementById('feet');
const calculateBtn = document.getElementById('calculate');
const resultEl = document.getElementById('result');

calculateBtn.addEventListener('click', () => {
    const total = parseInt(totalInput.value);
    const feet = parseInt(feetInput.value);
    let chicken = -1, rabbit = -1;

    for (let i = 0; i <= total; i++) {
        const j = total - i;
        if (2 * i + 4 * j === feet) {
            chicken = i;
            rabbit = j;
            break;
        }
    }

    if (chicken >= 0 && rabbit >= 0) {
        resultEl.style.color = 'blue';
        resultEl.textContent = `分别有鸡${chicken}只，有兔子${rabbit}只`;
    } else {
        resultEl.style.color = 'red';
        resultEl.textContent = '无解';
    }
});